<?php
require_once '../include/conn.php';
if($clause == "chklogin"){
    
	if($loginName == ''){hintAndBack('请输入帐号!',1);}
	if($loginPwd == ''){hintAndBack('请输入密码!',1);}
	session_start();
	if($code != $_SESSION['code']){hintAndBack('验证码错误!',1);}
	
	$md5Name = substr(md5(sha1(md5($loginName))),3);
	$md5Pwd = substr(md5(sha1(md5($loginPwd))),3);
	$rs = $db->get_one("SELECT * FROM `h_kefu_config` where h_admin = '$md5Name' and h_pass = '$md5Pwd'");
	if(!$rs)
	{
		hintAndBack('帐号或密码错误!',1);
	}
	else
	{
	
        $sql = "insert into `h_kefu_login` set ";
        $sql .= "h_user = '" . $md5Name . "', ";
        $sql .= "h_addTime = '" . date('Y-m-d H:i:s') . "', ";
        $sql .= "h_ip = '" . getUserIP() . "' ";
        $db->query($sql);
	
        setcookie("h_userName", $md5Name,NULL,'/');
        setcookie("h_passWord", $md5Pwd,NULL,'/');
        
        turnToPage("admin.php");
	}
	
	exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录 - 后台管理系统</title>
    <link rel="stylesheet" href="index.css">
</head>
<body>
    <?php
        function is_mobile() {
            $user_agent = $_SERVER['HTTP_USER_AGENT'];
            $mobile_browser = Array(
            "mqqbrowser","opera mobi","juc","iuc",
            "fennec","ios","applewebKit/420","applewebkit/525","applewebkit/532","ipad","iphone","ipaq","ipod",
            "iemobile", "windows ce",
            "240×320","480×640","acer","android","anywhereyougo.com","asus","audio","blackberry","blazer","coolpad" ,"dopod", "etouch", "hitachi","htc","huawei", "jbrowser", "lenovo","lg","lg-","lge-","lge", "mobi","moto","nokia","phone","samsung","sony","symbian","tablet","tianyu","wap","xda","xde","zte"
            );
            $is_mobile = false;
            foreach ($mobile_browser as $device) {
                if (stristr($user_agent, $device)) {
                    $is_mobile = true;
                    break;
                }
            }
            return $is_mobile;
        }

        if(is_mobile()){
    ?>
        <div class="login-wap">
            <div class="title">
                <img src="/img/kefu.png" alt="" width="50">
                <p>后台管理系统</p>
            </div>
            <div class="main"> 
                <form action="?clause=chklogin" method="post">
                    <div class="form-item">
                        <img src="/img/yhm.png" alt="">
                        <input type="text" name="loginName" placeholder="用户名" maxlength="20">
                    </div>
                    <div class="form-item">
                        <img src="/img/mm.png" alt="">
                        <input type="password" name="loginPwd" placeholder="密码" maxlength="20">
                    </div>
                    <div class="form-item">
                        <input type="text" name="code" placeholder="验证码" maxlength="4">
                        <img src="/include/getCode.php" onClick="this.src=this.src+'?'+Math.random();">
                    </div>      
                    <button>登录</button> 
                </form>
            </div>
        </div>
    <?php }else{ ?>
        <div class="login">
            <div class="main">
                <div class="title">
                    后台管理系统
                </div>
                <div class="login-box">
                    <div class="box-left">
                        <img src="/img/a.png" alt="">
                    </div>
                    <div class="box-right">
                        <form action="?clause=chklogin" method="post">
                            <div class="form-item">
                                <img src="/img/yhm.png" alt="">
                                <input type="text" name="loginName" placeholder="用户名" maxlength="20">
                            </div>
                            <div class="form-item">
                                <img src="/img/mm.png" alt="">
                                <input type="password" name="loginPwd" placeholder="密码" maxlength="20">
                            </div>
                            <div class="form-item">
                                <input type="text" name="code" placeholder="验证码" maxlength="4">
                                <img src="/include/getCode.php" onClick="this.src=this.src+'?'+Math.random();">
                            </div>      
                            <button>登录</button> 
                        </form>
                    </div>
                </div>
            </div>
        </div>
    <?php } ?>
</body>
</html>